#include "Resource.h"


ResourceMng* ResourceMng::_instance = NULL;


/**--------------------------------------------------------
*Description : Constructor
*Method name : ResourceMng
*Parameters :   
*Return value :
--------------------------------------------------------**/
ResourceMng::ResourceMng(LPDIRECT3DDEVICE9 d3ddv, LPDIRECT3DSURFACE9 backBuffer)
{
	this->d3ddv = d3ddv;
	this->backBuffer = backBuffer;

	//SURFACE, load hinh nen vao list vector
	
	surface_list.push_back(new Surface(this->d3ddv, this->backBuffer, L"..\\Resources\\Images\\background.jpg"));
	surface_list.push_back(new Surface(this->d3ddv, this->backBuffer, L"..\\Resources\\Images\\menu.jpg"));
	surface_list.push_back(new Surface(this->d3ddv, this->backBuffer, L"..\\Resources\\Images\\about.jpg"));
	surface_list.push_back(new Surface(this->d3ddv, this->backBuffer, L"..\\Resources\\Images\\gameover.jpg"));
	surface_list.push_back(new Surface(this->d3ddv, this->backBuffer, L"..\\Resources\\Images\\gamewin.jpg"));
	surface_list.push_back(new Surface(this->d3ddv, this->backBuffer, L"..\\Resources\\Images\\pause.jpg"));
	
	
	
	
	//TEXTURE, load hinh nhan vat vao list vector
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\land.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\mario_big.png", 5, 2, 10, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\mario_bullet.png", 5, 2, 10, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\mario_small.png", 6, 2, 12, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\mario_small_light.png", 6, 2, 12, D3DCOLOR_XRGB(253, 253, 253)));

	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\stone.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));

	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\brick_32.png", 2, 3, 6, D3DCOLOR_XRGB(253, 253, 253)));

	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\exp_brick.png", 2, 1, 2, D3DCOLOR_XRGB(253, 253, 253)));

	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\pipe_min.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\pipe_mid.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\pipe_max.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\pipe_ngang.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));

	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\cloud.png", 2, 1, 2, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\grass.png", 2, 1, 2, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\mountain.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\item_32.png", 4, 2, 8, D3DCOLOR_XRGB(253, 253, 253)));

	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\pirhana_32.png", 2, 1, 2, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\goomba_32.png", 11, 2, 22, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\turtle.png", 6, 2, 12, D3DCOLOR_XRGB(253, 253, 253)));

	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\score.png", 10, 1, 10, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\star.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));

	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\infomario.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\infocoin.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\infoworld.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\inforesult.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\infotime.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\checkpoint.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\bullet.png", 4, 2, 8, D3DCOLOR_XRGB(253, 253, 253)));

	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\dontquit.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\quitdontsave.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
	texture_list.push_back(new Texture(this->d3ddv, L"..\\Resources\\Images\\saveandquit.png", 1, 1, 1, D3DCOLOR_XRGB(253, 253, 253)));
}


/**--------------------------------------------------------
*Description : Destructor
*Method name : ~ResourceMng
*Parameters :   
*Return value :
--------------------------------------------------------**/
ResourceMng::~ResourceMng(void)
{
	surface_list.clear();
	texture_list.clear();
}


/**--------------------------------------------------------
*Description : Lay texture
*Method name : GetTexture
*Parameters :   LPWSTR fileName
*Return value : *TEXTURE
--------------------------------------------------------**/
Texture* ResourceMng::GetTexture(LPWSTR fileName)
{
	int size = texture_list.size();
	Texture* p_texture;

	for(int i = 0 ; i < size; ++i){
		p_texture = texture_list[i];

		if(p_texture->getFileName() == fileName){
			return p_texture;
		}
	}

	//GLMessage(L"Can not GetTexture");
	return NULL;
}


/**--------------------------------------------------------
*Description : Lay surface
*Method name : GetSurface
*Parameters :   LPWSTR fileName
*Return value : *SURFACE
--------------------------------------------------------**/
Surface* ResourceMng::GetSurface(LPWSTR fileName){
	int size = surface_list.size();
	Surface* p_surface;

	for(int i = 0 ; i < size; ++i){
		p_surface = surface_list[i];

		if(p_surface->getFileName() == fileName){
			return p_surface;
		}
	}

	//GLMessage(L"Can not GetSurface");
	return NULL;
}


/**--------------------------------------------------------
*Description : Lay doi tuong Resource
*Method name : GetInst
*Parameters :    
*Return value : *ResourceMng
--------------------------------------------------------**/
ResourceMng* ResourceMng::GetInst(LPDIRECT3DDEVICE9 d3ddv, LPDIRECT3DSURFACE9 backBuffer){
	if(_instance == NULL){
		_instance = new ResourceMng(d3ddv, backBuffer);
	}

	return _instance;
}
